/******************************************************************************
 **
 **    ISA Confidential
 **
 **    Source Materials
 **
 **    (C) COPYRIGHT LISA 2008-2009
 **
 **
 **  File Name:      TransitionsStrategy.java
 **  Description:
 **  Date:           2008-10-31
 **  Author:         LisaQian
 ******************************************************************************/
package com.ti.andon.workflow.command.transitions;

import java.util.HashMap;
import java.util.List;

import org.jbpm.JbpmContext;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.def.Transition;
import org.jbpm.taskmgmt.exe.TaskInstance;

import com.ti.andon.workflow.WFConstants;
import com.ti.andon.workflow.privilege.CandidateUsersStrategy;

public class TransitionsStrategy
{
	public List getAvailableTransitions(TaskInstance taskInstance,
			JbpmContext jbpmContext) throws Exception {
		return taskInstance.getAvailableTransitions();
	}
	
	// TODO No need to use this method currently.
	public List getCandidates(TaskInstance taskInstance, Transition transition) throws Exception
	{
		Long requester = null;
		String issueType = null;
		
		if (null != taskInstance)
		{
			ContextInstance ci = taskInstance.getContextInstance();
			requester = (Long) ci.getVariable(WFConstants.REQUESTER);
			issueType = (String) ci.getVariable(WFConstants.EQUIPMENT_ISSUE_TYPE);
		}		
		
		HashMap resolveContext = new HashMap();
		resolveContext.put(CandidateUsersStrategy.KEY_REQUEST_ID, requester);
		resolveContext.put(CandidateUsersStrategy.KEY_EQUIPMENT_ISSUE_TYPE, issueType);
		
		String transitionName = transition.getName();
		List candidateUsers = null;
		CandidateUsersStrategy strategy = (CandidateUsersStrategy) WFConstants.transitionCandidateUsersStrategy
				.get(transitionName);
		if (null != strategy)
		{
			candidateUsers = strategy.getCandidateUsers(resolveContext);
		}

		return candidateUsers;
	}

}
